<?php
$error_message = "";
if (isset($_POST['username']) && isset($_POST['password'])) {
    $username = $_POST["username"];
    $password = $_POST["password"];
    $string_exp = "/^[A-Za-z .'-]+$/";
    if (!preg_match($string_exp, $username)) {
        $error_message = 'Enter valid username *.<br />';
    }
    $pswd_exp = "/^[A-Za-z0-9 .'-]+$/";
    if (!preg_match($pswd_exp, $password)) {
        $error_message = 'Enter valid password *.<br />';
    }
    if (strlen($error_message) == 0) {
        try {
            $conn = mysql_connect('localhost', 'root', '');
            if (!$conn) {
                die("Could not connect :" . mysql_error());
            } else {
                mysql_select_db("j2eedevelopers", $conn);
                $cdt = date("d/m/y : H:i:s", time());
                //echo "connected successfully";
                //echo ("INSERT INTO ADMIN (USERNAME,PASSWORD) VALUES('$username','$password')");
                mysql_query("INSERT INTO admin (cdt, username,password) VALUES('$cdt', '$username','$password')");
                //echo 'Query successfully';
                mysql_close($conn);
            }
        } catch (Exception $e) {
            die('Could not insert :' . $e->getMessage());
        }
        if (empty($error_message)) {
            header("location:adminreports.php");
        }
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Coming Soon</title>
<link href="tools/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="tools/jquery.min.js"></script>
<script type="text/javascript" src="tools/cufon-yui.js"></script>
<script type="text/javascript" src="tools/Bebas_400.font.js"></script>
<script type="text/javascript" src="tools/Bell_Gothic_Std_300.font.js"></script>
<script type="text/javascript">
            Cufon.replace('a.logo', {fontFamily: 'Bebas'});
            Cufon.replace('a.logo span', {fontFamily: 'Bell Gothic Std'});
        </script>
<link rel="stylesheet" href="css/style.css" />
<!-- style ends here -->
</head>
<body>
<div class="main_container container">
  <div class="header"> <a class="logo" href="#">J2EEDEVELOPERS.NET<span>developer's network</span></a> </div>
  <div class="content myAdminLoginBox">
    <p align="center"><font face="Arial" size="2">Please login using the username 
      and password provided to you.</font></p>
    <div align="center"/>
    <table border="0" width="60%" id="table1" cellspacing="0" cellpadding="0"/>
    <tr>
      <td span="2" style="padding-left: 360px;color:red;"><?php echo $error_message ?> </td>
    </tr>
    </table>
    <form method="post">
      Username*:
      <input type="text" name="username" value=""/>
      <br/>
      Password*:
      <input type="password" name="password" value=""/>
      <br/>
      <input type="submit" name="Submit" value="Submit" class="submitBtn"/>
    </form>
  </div>
</div>
</body>
</html>
